#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys, os
from optparse import OptionParser

from cluster import ClusterConfig

def main():
    cluster = ClusterConfig(options.home_dir, options.cluster_name)
    datanode_list = ','.join(cluster.get_slaves())

    command = ' '.join(args)
    pdsh = 'pdsh -f %d -w %s "%s"' % (options.pdsh, datanode_list, command)
    print pdsh
    os.system(pdsh)

if __name__ == '__main__':
    parser = OptionParser()
    parser.add_option("-H", "--home_dir",  dest="home_dir",    type='string', help="htest home dir", default="/share/home/testhdp")
    parser.add_option("-c", "--cluster",   dest="cluster_name",type='string', help="cluster name",   default="cluster1")
    parser.add_option("-f", "--pdsh",      dest="pdsh",        type='int',    help="pdsh -f option", default=256)
    (options, args) = parser.parse_args()
    main()
